/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.analysys.presto.connector.hbase;

import io.airlift.configuration.Config;
import io.airlift.log.Logger;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.net.InetAddress;
import java.util.Arrays;

/**
 * HBase config
 *
 * @author wupeng
 * @date 2019/01/29
 */
@Slf4j
public class HBaseConfig {

    /**
     * A path that contains json files which define HBase table meta info.
     * This path means the default namespace of HBase.
     * metaDir:
     *   --schemas(namespaces)
     *     --table_A.json
     *     --table_B.json
     *   --table_C.json
     */
    private String metaDir;

    private String hbaseConfigResources;

    private boolean enableClientSideScan = false;

    /**
     * Table names that using ClientSideRegionScanner to do query operation.
     * namespace_1:tableName_1,namespace_2:tableName_2,namespace_2:tableName_3
     * Set * if all tables are using ClientSideRegionScanner
     */
    private String clientSideQueryModeTableNames;


    /**
     * 连接池最大连接数
     */
    private int connectionPoolMax = 10;


    /**
     * 连接池最小连接数
     */
    private int connectionPoolMin = 1;


    @NotNull
    public String getMetaDir() {
        return metaDir;
    }

    @Config("meta-dir")
    public void setMetaDir(String metaDir) {
        this.metaDir = metaDir;
    }


    public String getHbaseConfigResources() {
        return hbaseConfigResources;
    }

    @Config("hbase.config.resources")
    public void setHbaseConfigResources(String hbaseConfigResources) {
        this.hbaseConfigResources = hbaseConfigResources;
    }

    public boolean isEnableClientSideScan() {
        return enableClientSideScan;
    }

    @Config("enable-clientSide-scan")
    public void setEnableClientSideScan(boolean enableClientSideScan) {
        this.enableClientSideScan = enableClientSideScan;
    }

    public String getClientSideQueryModeTableNames() {
        return clientSideQueryModeTableNames;
    }

    @Config("clientside-querymode-tablenames")
    public void setClientSideQueryModeTableNames(String clientSideQueryModeTableNames) {
        this.clientSideQueryModeTableNames = clientSideQueryModeTableNames;
    }


    @Max(100)
    public int getConnectionPoolMax() {
        return connectionPoolMax;
    }

    @Config("hbase.connectionPool.max")
    public void setConnectionPoolMax(int connectionPoolMax) {
        this.connectionPoolMax = connectionPoolMax;
    }

    @Min(1)
    public int getConnectionPoolMin() {
        return connectionPoolMin;
    }

    @Config("hbase.connectionPool.min")
    public void setConnectionPoolMin(int connectionPoolMin) {
        this.connectionPoolMin = connectionPoolMin;
    }

    @Override
    public String toString() {
        return "HBaseConfig{" +
                ", hbaseConfigResources='" + hbaseConfigResources + '\'' +
                ", metaDir='" + metaDir + '\'' +
                '}';
    }

}
